package com.ruoyi.web.controller.pos;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.pos.domain.PosCustomer;
import com.ruoyi.pos.service.IPosCustomerService;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pos/pos_customer")
public class PosCustomerController extends BaseController {

    @Autowired
    private IPosCustomerService posCustomerService;

    @GetMapping("/customerDengLu")
    public PosCustomer customerDengLu(PosCustomer posCustomer) {
        List<PosCustomer> posCustomerList = posCustomerService.selectPosCustomerList(posCustomer);
        if(posCustomerList != null && posCustomerList.size()>0){
            return posCustomerList.get(0);
        }else {
            return null;
        }
    }
    @GetMapping("/insert_pos_customer")
    public int insertPosCustomer(PosCustomer posCustomer){
        PosCustomer posCustomer1 = new PosCustomer();
        posCustomer1.setPhone(posCustomer.getPhone());
        List<PosCustomer> posCustomerList = posCustomerService.selectPosCustomerList(posCustomer1);
        if(posCustomerList == null || posCustomerList.size() == 0){
            posCustomer.setAddress("北京市海淀区");
            int successId = posCustomerService.insertPosCustomer(posCustomer);
            return successId;
        }else{
            return 2;
        }
    }
    @GetMapping("/check_phone")
    public List<PosCustomer> checkPhone(PosCustomer posCustomer){
        List<PosCustomer> posCustomerList = posCustomerService.selectPosCustomerList(posCustomer);
        return posCustomerList;
    }
    @GetMapping("/update_pos_customer")
    public int updatePosCustomer(PosCustomer posCustomer){
        int updatePosCustomerSuccessId = posCustomerService.updatePosCustomer(posCustomer);
        return updatePosCustomerSuccessId;
    }
}
